package org.bluweb.g4wicket.map.service;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

import org.bluweb.g4wicket.G4WicketException;

import com.google.gson.Gson;


public class GeocodingService {

	public GeocodingResponse geocode( GeocodingRequest request ) {

		try {
			URL url = new URL( "http://maps.google.com/maps/api/geocode/json?sensor=false&address=" + request.getAddress() );
			BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream() ) );
			return new Gson().fromJson( reader, GeocodingResponse.class );
		} catch (Exception e) {
			throw new G4WicketException( e );
		}
	}
}
